package demo

import (
	"path"
	serviceStorage "server/service/storage"
	"server/utils"

	"github.com/gin-gonic/gin"
)

func CosPutHandle(c *gin.Context) {
	file, _ := c.FormFile("file")
	fileName := file.Filename
	dst := path.Join("./upload", fileName)
	c.SaveUploadedFile(file, dst)
	cosUrl, errRes := serviceStorage.CosPut(dst, fileName)
	if errRes != nil {
		c.AbortWithError(500, errRes)
		return
	}
	// 正常返回数据
	c.JSON(
		200,
		utils.DealResponse(utils.Response{
			"data": gin.H{
				"url": cosUrl,
			},
		}),
	)
}
